const db = require('../db/index.js')
const router = require('../router/lookfor.js')

exports.Lookfor = (req,res)=>{
	var chr='%'
	for(i =0;i<req.query.lookfor.length;i++){
		chr+=req.query.lookfor[i]+'%'
	}
	//这里会给你变成字符串，注意用typeof检验
	var state1=req.query.state
	var isLogin = req.query.isLogin	
	
	sql = `select * from ev_articles where title like '${chr}' and state ='${state1}'`
	if(isLogin!="false"){
		sql = `select * from ev_articles where title like '${chr}' and state = '${state1}' and author_id = ${req.user.id}`
	}
	db.query(sql,(err,results)=>{
		if (err)
				return res.cc(err)
		if (results.length <= 0) 
				return res.cc('无相关数据!')
		
		res.send({
			status:0,
			data:results,
			message:"查找成功!"
		})
	})
}